<?php
require_once ( LIB_DIR.'search/moviesearch.php');

/**
 * 最热
 *
 * @author Jensen
 */
class hotest extends AbstractAction {

    public function run() {
        global $TPL;

        // 获得最热电影
        $hotMovies = array();
        $movieIds = $this->searchHotest(2);
        if( $movieIds['total'] > 0 ) {
            $movieDao = $this->getDao("MovieDAO");
            $hotMovies = $movieDao->GetMovieInfoByIdList( $movieIds['matchIds'], MOVIE_PERPAGE );
            foreach ($hotMovies as &$item) {
                // set large images
                $item['largeImgUrl'] = $this->getLargeImgUrl($item['imgUrl']);
            }
        }
        $TPL->assign('hotmovies', $hotMovies);

        // 获得最热电视剧
        $hotTvs = array();
        $tvIds = $this->searchHotest(1);
        if( $tvIds['total'] > 0 ) {
            $movieDao = $this->getDao("MovieDAO");
            $hotTvs = $movieDao->GetMovieInfoByIdList( $tvIds['matchIds'], MOVIE_PERPAGE );
            foreach ($hotMovies as &$item) {
                // set large images
                $item['largeImgUrl'] = $this->getLargeImgUrl($item['imgUrl']);
            }
        }
        $TPL->assign('hottvs', $hotTvs);
        
        $TPL->assign('current_page', 'hotest');
        $TPL->assign('items', $items);
        $TPL->display('theme_v2/hotest.tpl');
    }
    
    private function searchHotest( $movietype ){
        
        $sortfield = "viewcount";
        $isdesc = true;
        
        if( debug ){
            $search = new moviesearch( "42.121.129.20", 9312 );
        }
        else{
            $search = new moviesearch();
        }
        
        // condition filter
        $conditions = array();
        $conditions['movietype'] = array($movietype);
        $conditions['updatetime'] = (time()-3600*24*14).",".time();
        
        $result = $search->MultiFilterAndSortQuery( "", $conditions, $sortfield, 1, $isdesc );
        
        return $result;
    }

}

?>
